package com.xlhj.boot.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author: liucaijing
 * @description: TtlMsgQueueListener
 * @date: 2021/10/20 9:05
 */
@Component
public class TtlMsgQueueListener {

    private static final String TTL_MSG_QUEUE = "ttl-msg-queue";
    private static Logger logger = LoggerFactory.getLogger(TtlMsgQueueListener.class);

    @RabbitListener(queues = TTL_MSG_QUEUE)
    public void receiveMsg(Message message) {
        String msg = new String(message.getBody());
        logger.info("接收到TTL队列消息：{}", msg);
        String correlationId = message.getMessageProperties().getCorrelationId();
        System.out.println(correlationId);
        String userId = message.getMessageProperties().getHeaders().get("userId").toString();
        System.out.println(userId);
    }
}
